#ifndef VSANIMBLENDFUNCTION_H
#define VSANIMBLENDFUNCTION_H
#include "VSAnimFunction.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSAnimBlendFunction : public VSAnimFunction
	{
		//RTTI
		DECLARE_RTTI;

		enum  //Cross Fading Tye
		{
			CFT_SMOOTH,
			CFT_IMMEDIATE,
			CFT_MAX
		};
	public:
		
		virtual ~VSAnimBlendFunction() = 0;
		virtual bool UpdateEx(double dAppTime);

		VSAnimBlendFunction(const VSUsedName & ShowName,VSAnimTree * pAnimTree);
		
		inline void SetCrossFadingType(unsigned int uiCrossFadingType)
		{
			if (uiCrossFadingType >= CFT_MAX)
			{
				uiCrossFadingType = CFT_SMOOTH;
			}
			m_uiCrossFadingType = uiCrossFadingType;
		}
		static void LineBlendTwo(VSAnimFunction * pOut,
						VSAnimFunction * pAnimFunction1,VSAnimFunction * pAnimFunction2,VSREAL fWeight);
		static void LineBlendThree(VSAnimFunction *pOut,
			VSAnimFunction * pAnimFunction1,VSAnimFunction * pAnimFunction2,VSAnimFunction * pAnimFunction3,
									VSREAL fWeight1,VSREAL fWeight2);

		static void LineBlendTwo(VSArray<VSAnimAtom> *pOut,
			const VSArray<VSAnimAtom> * pIn1,const VSArray<VSAnimAtom> *pIn2,VSREAL fWeight);
		static void LineBlendThree(VSArray<VSAnimAtom> *pOut,
			const VSArray<VSAnimAtom> * pIn1,const VSArray<VSAnimAtom> *pIn2,const VSArray<VSAnimAtom> *pIn3,
			VSREAL fWeight1,VSREAL fWeight2);

		static void LineBlendTwo(VSArray<VSAnimAtom> *pOut,
			VSAnimFunction * pAnimFunction1,VSAnimFunction * pAnimFunction2,VSREAL fWeight);
		static void LineBlendThree(VSArray<VSAnimAtom> *pOut,
			VSAnimFunction * pAnimFunction1,VSAnimFunction * pAnimFunction2,VSAnimFunction * pAnimFunction3,
			VSREAL fWeight1,VSREAL fWeight2);
	protected:
		VSAnimBlendFunction();
		virtual bool ComputePara(double dAppTime) = 0;
		virtual bool ComputeOutBoneMatrix(double dAppTime) = 0;
		unsigned int m_uiCrossFadingType;

		//use for CFT_IMMEDIATE
		VSArray<VSREAL> m_NodeCrossFadingTime;
		VSREAL			m_fCrossFadingTime;
		unsigned int	m_uiLastAnimIndex;
	public:
		inline void SetNodeCrossFadingTime(unsigned int uiIndex,VSREAL fTime)
		{
			if (uiIndex >= m_pInput.GetNum())
			{
				return ;
			}
			m_NodeCrossFadingTime[uiIndex] = fTime;
		}
	public:
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);

	};
	typedef VSPointer<VSAnimBlendFunction> VSAnimBlendFunctionPtr;
}
#endif